package com.loubii.sunshineSchool.ui.card;

import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.loubii.sunshineSchool.R;
import com.loubii.sunshineSchool.httpRequest.HttpBin;
import com.loubii.sunshineSchool.pojo.ApplyDetail;
import com.loubii.sunshineSchool.ui.avtivity.BaseToolBarActivity;
import com.loubii.sunshineSchool.util.ImageUtil;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Response;

public class SSReasonActivity extends BaseToolBarActivity {

    @BindView(R.id.iv_classify)
    ImageView pic;
    @BindView(R.id.tv_classify)
    TextView name;
    @BindView(R.id.tv_classify_describe)
    TextView describe;
    @BindView(R.id.tv_name)
    TextView reason;
    @BindView(R.id.bt_next)
    Button choose;

    int bid;
    int uid;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    protected void initData() {
        uid = getIntent().getIntExtra("uid", 0);
        bid = getIntent().getIntExtra("bid", 0);
        HttpBin.applyDetail(this, uid, bid, new HttpBin.ResponseListener<ApplyDetail>() {
            @Override
            public void onResponse(Call<ApplyDetail> call, Response<ApplyDetail> response) {
                ImageUtil.downloadAvatar(response.body().getUserItem().getImage(), pic);
                name.setText(response.body().getUserItem().getUserName());
                describe.setText(response.body().getUserItem().getSecondTitle());
                reason.setText(response.body().getReason());
            }

            @Override
            public void onFailure(Call<ApplyDetail> call, Throwable t) {

            }
        });
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_transfer;
    }

    @Override
    protected void initView() {
        ((Toolbar) findViewById(R.id.tb_base_title)).setTitle("TA的理由");
        choose.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                HttpBin.choosePerson(SSReasonActivity.this, uid, bid, new HttpBin.ResponseListener<Boolean>() {
                    @Override
                    public void onResponse(Call<Boolean> call, Response<Boolean> response) {
                        if (response.body()) {
                            Toast.makeText(SSReasonActivity.this, "选择成功~", Toast.LENGTH_LONG).show();
                        } else {
                            Toast.makeText(SSReasonActivity.this, "你应经选择了参与者，活动已经完结啦~", Toast.LENGTH_LONG).show();
                        }
                    }

                    @Override
                    public void onFailure(Call<Boolean> call, Throwable t) {

                    }
                });
            }
        });
    }
}
